package com.zxkj.commonpatrol.ui;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.content.Intent;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;

import com.alibaba.android.arouter.launcher.ARouter;
import com.czy.basecommon.utils.base.BaseVmDataBindingActivity;

import com.czy.basecommon.utils.entity.event.SearchData;
import com.czy.basecommon.utils.tools.ActivityTool;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.jeremyliao.liveeventbus.LiveEventBus;
import com.luck.picture.lib.PhotoEditorActivity;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.luck.picture.lib.model.EditPicEvent;
import com.xuexiang.xui.utils.WidgetUtils;
import com.xuexiang.xui.widget.dialog.MiniLoadingDialog;
import com.xuexiang.xui.widget.toast.XToast;
import com.zxkj.commonpatrol.BR;
import com.zxkj.commonpatrol.R;
import com.zxkj.commonpatrol.adapt.AnwerAdapt;
import com.zxkj.commonpatrol.adapt.MyMediaAdapt;
import com.zxkj.commonpatrol.databinding.ActivityNewExceptionBinding;
import com.zxkj.commonpatrol.model.entity.AnwerBean;
import com.zxkj.commonpatrol.model.entity.Group;
import com.zxkj.commonpatrol.model.entity.GroupMember;
import com.zxkj.commonpatrol.model.entity.GruopBean;
import com.zxkj.commonpatrol.model.entity.MyMediaEntry;

import com.zxkj.commonpatrol.model.entity.itemPicEntity;
import com.zxkj.commonpatrol.model.entity.itemVideoEntity;
import com.zxkj.commonpatrol.model.entity.itemVioceEntity;
import com.zxkj.commonpatrol.utils.AudioRecorderButton;
import com.zxkj.commonpatrol.utils.VideoRecordActivity;
import com.zxkj.commonpatrol.view.MyAudioRecorderButton;
import com.zxkj.commonpatrol.viewmodel.NewExceptionViewModel;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

public class NewExceptionActivity extends BaseVmDataBindingActivity<ActivityNewExceptionBinding, NewExceptionViewModel> implements
        GoogleMap.OnMyLocationButtonClickListener,
        GoogleMap.OnMyLocationClickListener,
        OnMapReadyCallback{
    private GoogleMap mMap;
    private int i=0;
    private FusedLocationProviderClient mFusedLocationProviderClient;
    private MyMediaAdapt myMediaAdapt1;
    private MyMediaAdapt myMediaAdapt2;
    private MyMediaAdapt myMediaAdapt3;
    private static final int REQUEST_VIDEO = 99;
    private static final int REQUEST_VIDEO2 = 100;
    private static final int REQUEST_VIDEO3 = 101;

    private List<LocalMedia> selectListData1 = new ArrayList<>();//group1
    private List<LocalMedia> selectListData2 = new ArrayList<>();//group2
    private List<LocalMedia> selectListData3 = new ArrayList<>();//group3
    private MiniLoadingDialog miniLoadingDialog;
    private boolean a;
    private String add;

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_new_exception;
    }

    @Override
    public int initVariableId() {
        return BR.mNewExceptionViewModel;
    }



    @Override
    protected void initUI() {
        if (getIntent().hasExtra("a")){
             a = getIntent().getBooleanExtra("a", false);
        }
        if (getIntent().hasExtra("add")){
            add = getIntent().getStringExtra("add");
            if (add.equals("1")){
               binding.llType.setVisibility(View.VISIBLE);
                binding.llProblem.setVisibility(View.VISIBLE);
            }
        }


        miniLoadingDialog = WidgetUtils.getMiniLoadingDialog(this);
//        miniLoadingDialog.show();
        EventBus.getDefault().register(this);
        SupportMapFragment mapFragment =
                (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
        mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);

        //初始化recyleview
        LinearLayoutManager layoutManager1 = new LinearLayoutManager(this);
        layoutManager1.setOrientation(LinearLayoutManager.HORIZONTAL);
        binding.recyGroup1Pic.setLayoutManager(layoutManager1);

        LinearLayoutManager layoutManager2 = new LinearLayoutManager(this);
        layoutManager2.setOrientation(LinearLayoutManager.HORIZONTAL);
        binding.recyGroup2Pic.setLayoutManager(layoutManager2);


        LinearLayoutManager layoutManager3 = new LinearLayoutManager(this);
        layoutManager3.setOrientation(LinearLayoutManager.HORIZONTAL);
        binding.recyGroup3Pic.setLayoutManager(layoutManager3);

        LinearLayoutManager layoutManager4 = new LinearLayoutManager(this);

        binding.recyAnser.setLayoutManager(layoutManager4);

        myMediaAdapt1 = new MyMediaAdapt(getSupportFragmentManager(),1,this);//第一組
        binding.recyGroup1Pic.setAdapter(myMediaAdapt1);


        myMediaAdapt2 = new MyMediaAdapt(getSupportFragmentManager(),2,this);//第二組
        binding.recyGroup2Pic.setAdapter(myMediaAdapt2);


        myMediaAdapt3 = new MyMediaAdapt(getSupportFragmentManager(),3,this);//第三組
        binding.recyGroup3Pic.setAdapter(myMediaAdapt3);
        binding.llGroup2.setVisibility(View.GONE);
        binding.llGroup3.setVisibility(View.GONE);

    }

    @Override
    protected void initData() {
      if (a){
          List<AnwerBean> Anwer=new ArrayList<>();
          AnwerBean anwerBean =new AnwerBean();
          anwerBean.setTitle("空調管漏水");
          Anwer.add(anwerBean);
          AnwerBean anwerBean1 =new AnwerBean();
          anwerBean1.setTitle("空調指示燈不亮");
          Anwer.add(anwerBean1);
          AnwerAdapt anwerAdapt=new AnwerAdapt(R.layout.item_anwer,Anwer);
          binding.recyAnser.setAdapter(anwerAdapt);
      }
    }


    @RequiresApi(api = Build.VERSION_CODES.N)
    @Override
    protected void setListener() {
        super.setListener();
        //第一组语音回调
        binding.addVo.setAudioFinishRecorderListener((seconds, filePath) -> {
            myMediaAdapt1.addData(new MyMediaEntry(2,new itemVioceEntity(0,filePath),null,null));
            long counts = myMediaAdapt1.getData().stream().filter(p -> p.getVioceEntity() != null).map(p -> p.getVioceEntity()).count();
            int count = Integer.parseInt(String.valueOf(counts));
            binding.addVo.setCountss(count);
        });
        //第二组语音回调
        binding.addVo2.setAudioFinishRecorderListener((seconds, filePath) -> {
            myMediaAdapt2.addData(new MyMediaEntry(2,new itemVioceEntity(0,filePath),null,null));
            long counts = myMediaAdapt2.getData().stream().filter(p -> p.getVioceEntity() != null).map(p -> p.getVioceEntity()).count();
            int count = Integer.parseInt(String.valueOf(counts));
            binding.addVo2.setCountss(count);
        });
        //第三组语音回调
        binding.addVo3.setAudioFinishRecorderListener((seconds, filePath) -> {
            myMediaAdapt3.addData(new MyMediaEntry(2,new itemVioceEntity(0,filePath),null,null));
            long counts = myMediaAdapt3.getData().stream().filter(p -> p.getVioceEntity() != null).map(p -> p.getVioceEntity()).count();
            int count = Integer.parseInt(String.valueOf(counts));
            binding. addVo3.setCountss(count);
        });


        binding.ivAddPo.setOnClickListener(v->{
            addPic(myMediaAdapt1,PictureConfig.CHOOSE_REQUEST1);

        });
        binding.ivAddPo2.setOnClickListener(v->{
            addPic(myMediaAdapt2,PictureConfig.CHOOSE_REQUEST2);

        });
        binding.ivAddPo3.setOnClickListener(v->{
            addPic(myMediaAdapt3,PictureConfig.CHOOSE_REQUEST3);

        });
        binding.addVe.setOnClickListener(v->{
            addVideo(myMediaAdapt1,REQUEST_VIDEO);

        });
        binding.addVe2.setOnClickListener(v->{
            addVideo(myMediaAdapt2,REQUEST_VIDEO2);


        });

        binding.addVe3.setOnClickListener(v->{
            addVideo(myMediaAdapt3,REQUEST_VIDEO3);



        });

        binding.ivDeleteGroup2.setOnClickListener(v->{
            binding.llGroup2.setVisibility(View.GONE);
            binding.ivAddGroup.setVisibility(View.VISIBLE);
            myMediaAdapt2.getData().clear();
            myMediaAdapt2.MyNotifyDataSetChanged();


        });

        binding.ivDeleteGroup3.setOnClickListener(v->{
            binding.ivAddGroup.setVisibility(View.VISIBLE);
            binding.llGroup3.setVisibility(View.GONE);
            myMediaAdapt3.getData().clear();
            myMediaAdapt3.MyNotifyDataSetChanged();


        });

        binding.ivAddGroup.setOnClickListener(v->{
            if( binding.llGroup3.getVisibility()==View.VISIBLE&& binding.llGroup2.getVisibility()==View.GONE){
                binding. llGroup2.setVisibility(View.VISIBLE);
                binding. ivAddGroup.setVisibility(View.GONE);
            }else if ( binding.llGroup3.getVisibility()==View.GONE&& binding.llGroup2.getVisibility()==View.VISIBLE){
                binding. llGroup3.setVisibility(View.VISIBLE);
                binding.ivAddGroup.setVisibility(View.GONE);
            }else if( binding.llGroup3.getVisibility()==View.GONE&& binding.llGroup2.getVisibility()==View.GONE){
                binding.llGroup2.setVisibility(View.VISIBLE);
            }

        });







        binding.btnSubmit.setOnClickListener(v -> {
            List<GroupMember> groups=new ArrayList<>();
            String trim = binding.etDescribe.getText().toString().trim();
            if (TextUtils.isEmpty(trim)){
                XToast.error(this, R.string.exception_is_not_null).show();
                return;
            }


            myMediaAdapt1.getPic();
            myMediaAdapt1.getVideo();
            myMediaAdapt1.getVioce();
            if (myMediaAdapt1.getVioce().size()>0||myMediaAdapt1.getVideo().size()>0||myMediaAdapt1.getPic().size()>0){
                GroupMember groupMember =new GroupMember();
                groupMember.setPicData( myMediaAdapt1.getPic());
                groupMember.setVideoData(myMediaAdapt1.getVideo());
                groupMember.setVioceData(myMediaAdapt1.getVioce());
                groups.add(groupMember);
            }


            myMediaAdapt2.getPic();
            myMediaAdapt2.getVideo();
            myMediaAdapt2.getVioce();
            if (myMediaAdapt2.getVioce().size()>0||myMediaAdapt2.getVideo().size()>0||myMediaAdapt2.getPic().size()>0){
                GroupMember groupMember =new GroupMember();
                groupMember.setPicData( myMediaAdapt2.getPic());
                groupMember.setVideoData(myMediaAdapt2.getVideo());
                groupMember.setVioceData(myMediaAdapt2.getVioce());
                groups.add(groupMember);
            }

            myMediaAdapt3.getPic();
            myMediaAdapt3.getVideo();
            myMediaAdapt3.getVioce();
            if (myMediaAdapt3.getVioce().size()>0||myMediaAdapt3.getVideo().size()>0||myMediaAdapt3.getPic().size()>0){
                GroupMember groupMember =new GroupMember();
                groupMember.setPicData( myMediaAdapt3.getPic());
                groupMember.setVideoData(myMediaAdapt3.getVideo());
                groupMember.setVioceData(myMediaAdapt3.getVioce());
                groups.add(groupMember);
            }

            Group gruopBean =new Group();
            gruopBean.setTitle(trim);
            gruopBean.setmMemberList(groups);
            LiveEventBus.get("cs").post(gruopBean);
            ActivityTool.getInstance().popOneActivity(this);

        });


       binding.llProblem.setOnClickListener(v->{
           Bundle bundle =new Bundle();
           bundle.putString("name","2");
           ARouter.getInstance().build("/login/SeachActivity").with(bundle).navigation();
       });

        binding.llType.setOnClickListener(v->{
            Bundle bundle =new Bundle();
            bundle.putString("name","1");
            ARouter.getInstance().build("/login/SeachActivity").with(bundle).navigation();
        });



    }

    @Override
    public boolean onMyLocationButtonClick() {
        return false;
    }

    @Override
    public void onMyLocationClick(@NonNull Location location) {

    }

    @Override
    public void onMapReady(GoogleMap map) {
        mMap = map;

        mMap.setOnMyLocationButtonClickListener(this);
        mMap.setOnMyLocationClickListener(this);



        enableMyLocation();
    }

    private void enableMyLocation() {
        if (mMap != null) {
            mMap.setMyLocationEnabled(true);
            updateLocationUI();
            getDeviceLocation();
        }
    }

    private void getDeviceLocation() {
        try {
            i++;

                Task locationResult = mFusedLocationProviderClient.getLastLocation();
                locationResult.addOnCompleteListener(this, new OnCompleteListener() {
                    @Override
                    public void onComplete(@NonNull Task task) {
                        if (task.isSuccessful()) {
                            // Set the map's camera position to the current location of the device.

//                            miniLoadingDialog.dismiss();
                            Location mLastKnownLocation = (Location) task.getResult();
                            if (mLastKnownLocation==null){
                                return;
                            }
                            double latitude = mLastKnownLocation.getLatitude();
                            double longitude = mLastKnownLocation.getLongitude();


                            mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(
                                    new LatLng(latitude,
                                            longitude), 18));



                            Geocoder geocoder = new Geocoder(NewExceptionActivity.this, Locale.getDefault());
                            List<Address> addresses = null;
                            try {
                                addresses = geocoder.getFromLocation(latitude, longitude, 1);
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                            if (addresses != null&& addresses.size() > 0) {
                                String locality = addresses.get(0).getLocality() + addresses.get(0).getFeatureName();
                                binding.tvAddress.setText(locality);

                            } else {
                                mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(null, 18));
                                mMap.getUiSettings().setMyLocationButtonEnabled(false);
                            }


                        } else {
                            miniLoadingDialog.dismiss();
                            mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(null, 18));
                            mMap.getUiSettings().setMyLocationButtonEnabled(false);
                        }
                    }
                });

        } catch(SecurityException e)  {
//            miniLoadingDialog.dismiss();
            Log.e("Exception: %s", e.getMessage());
        }
    }

    private void updateLocationUI() {
        if (mMap == null) {
            return;
        }

        mMap.setMyLocationEnabled(true);
        mMap.getUiSettings().setZoomControlsEnabled(true);
        mMap.setMinZoomPreference(18);
    }


    @Override
    protected void dataObserver() {
        super.dataObserver();
        LiveEventBus.get("diss",Boolean.class).observe(this, new Observer<Boolean>() {
            @Override
            public void onChanged(Boolean aBoolean) {
                if (aBoolean){
                    binding.scrollView.requestDisallowInterceptTouchEvent(false);
                }else{
                    binding.scrollView.requestDisallowInterceptTouchEvent(true);
                }
            }
        });

        LiveEventBus.get("3", SearchData.class).observe(this, new Observer<SearchData>() {
            @Override
            public void onChanged(SearchData searchData) {
                if (searchData.isSelect()){
                    binding.etType.setText(searchData.getName());
                }else{
                    binding.etType.setText("請選擇類型");
                }
            }
        });
        LiveEventBus.get("4", SearchData.class).observe(this, new Observer<SearchData>() {
            @Override
            public void onChanged(SearchData searchData) {
                if (searchData.isSelect()){
                    binding.etProblem.setText(searchData.getName());
                }else{
                    binding.etProblem.setText("請選擇問題");
                }
            }
        });
    }

    private void setImage(int x) {

        PictureSelector.create(NewExceptionActivity.this)// 是否可预览图片 true or false
                .openCamera(PictureMimeType.ofImage())
                .compress(true)
                .forResult(x);

    }


    public AudioRecorderButton getGroup1MyAudioRecorderButton(){

        return   binding.addVo;

    }
    public AudioRecorderButton getGroup2MyAudioRecorderButton(){

        return    binding.addVo2;

    }
    public AudioRecorderButton getGroup3MyAudioRecorderButton(){

        return    binding.addVo3;

    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                case PictureConfig.CHOOSE_REQUEST1:
                    // 图片、视频、音频选择结果回调
                    List<LocalMedia> selectList = PictureSelector.obtainMultipleResult(data);
                    LocalMedia localMedia1 = selectList.get(0);
                    selectListData1.add(localMedia1);
                    // 例如 LocalMedia 里面返回三种path
                    // 1.media.getPath(); 为原图path
                    // 2.media.getCutPath();为裁剪后path，需判断media.isCut();是否为true  注意：音视频除外
                    // 3.media.getCompressPath();为压缩后path，需判断media.isCompressed();是否为true  注意：音视频除外
                    // 如果裁剪并压缩了，以取压缩路径为准，因为是先裁剪后压缩的
                    for (LocalMedia bean : selectList) {
                        String compressPath = bean.getCompressPath();

                        if (selectListData1.size() == 3) {

                        } else {

                        }

                        Intent intent = new Intent(NewExceptionActivity.this, PhotoEditorActivity.class);
                        intent.putExtra("paths", compressPath);
                        intent.putExtra("type", PictureConfig.CHOOSE_REQUEST1);
                        startActivity(intent);

                    }
                    break;
                case PictureConfig.CHOOSE_REQUEST2:
                    // 图片、视频、音频选择结果回调
                    List<LocalMedia> selectList1 = PictureSelector.obtainMultipleResult(data);
                    LocalMedia localMedia2 = selectList1.get(0);
                    selectListData2.add(localMedia2);
                    // 例如 LocalMedia 里面返回三种path
                    // 1.media.getPath(); 为原图path
                    // 2.media.getCutPath();为裁剪后path，需判断media.isCut();是否为true  注意：音视频除外
                    // 3.media.getCompressPath();为压缩后path，需判断media.isCompressed();是否为true  注意：音视频除外
                    // 如果裁剪并压缩了，以取压缩路径为准，因为是先裁剪后压缩的
                    for (LocalMedia bean : selectList1) {
                        String compressPath = bean.getCompressPath();

                        if (selectListData2.size() == 3) {

                        } else {

                        }

                        Intent intent = new Intent(NewExceptionActivity.this, PhotoEditorActivity.class);
                        intent.putExtra("paths", compressPath);
                        intent.putExtra("type", PictureConfig.CHOOSE_REQUEST2);
                        startActivity(intent);

                    }
                    break;
                case PictureConfig.CHOOSE_REQUEST3:
                    // 图片、视频、音频选择结果回调
                    List<LocalMedia> selectList2 = PictureSelector.obtainMultipleResult(data);
                    LocalMedia localMedia3 = selectList2.get(0);
                    selectListData3.add(localMedia3);
                    // 例如 LocalMedia 里面返回三种path
                    // 1.media.getPath(); 为原图path
                    // 2.media.getCutPath();为裁剪后path，需判断media.isCut();是否为true  注意：音视频除外
                    // 3.media.getCompressPath();为压缩后path，需判断media.isCompressed();是否为true  注意：音视频除外
                    // 如果裁剪并压缩了，以取压缩路径为准，因为是先裁剪后压缩的
                    for (LocalMedia bean : selectList2) {
                        String compressPath = bean.getCompressPath();

                        if (selectListData3.size() == 3) {

                        } else {

                        }

                        Intent intent = new Intent(NewExceptionActivity.this, PhotoEditorActivity.class);
                        intent.putExtra("paths", compressPath);
                        intent.putExtra("type", PictureConfig.CHOOSE_REQUEST3);
                        startActivity(intent);

                    }
                    break;
                case REQUEST_VIDEO:

                    String path = data.getStringExtra("path");
                    String imgPath = data.getStringExtra("imagePath");
                    int type = data.getIntExtra("type", -1);
                    if (type == 0) {
                        myMediaAdapt1.addData(new MyMediaEntry(3, null, null, new itemVideoEntity(path, imgPath)));
                    }
                    break;

                case REQUEST_VIDEO2:
                    String path2 = data.getStringExtra("path");
                    String imgPath2 = data.getStringExtra("imagePath");
                    int type2 = data.getIntExtra("type", -1);
                    if (type2 == 0) {
                        myMediaAdapt2.addData(new MyMediaEntry(3, null, null, new itemVideoEntity(path2, imgPath2)));
                    }
                    break;

                case REQUEST_VIDEO3:
                    String path3 = data.getStringExtra("path");
                    String imgPath3 = data.getStringExtra("imagePath");
                    int type3 = data.getIntExtra("type", -1);
                    if (type3 == 0) {
                        myMediaAdapt3.addData(new MyMediaEntry(3, null, null, new itemVideoEntity(path3, imgPath3)));
                    }
                    break;


            }
        }

    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
//        File file = new File(ETFConstant.VIOCEPATH);
//        FileHelper.deleteFile(file);
        EventBus.getDefault().unregister(this);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void getEditPic(EditPicEvent editEvent) {
        if (editEvent.isIsok()) {
            switch (editEvent.getIvType()) {
                case PictureConfig.CHOOSE_REQUEST1:
                    myMediaAdapt1.addData(new MyMediaEntry(1, null, new itemPicEntity(editEvent.getPath()), null));

                    break;
                case PictureConfig.CHOOSE_REQUEST2:
                    myMediaAdapt2.addData(new MyMediaEntry(1, null, new itemPicEntity(editEvent.getPath()), null));

                    break;
                case PictureConfig.CHOOSE_REQUEST3:
                    myMediaAdapt3.addData(new MyMediaEntry(1, null, new itemPicEntity(editEvent.getPath()), null));

                    break;
            }
        }
    }
    @RequiresApi(api = Build.VERSION_CODES.N)
    private void addVideo(MyMediaAdapt adapt,int i) {
        long counts = adapt.getData().stream().filter(p -> p.getItemVideoEntity() != null).map(p -> p.getItemVideoEntity()).count();
        int count = Integer.parseInt(String.valueOf(counts));
        if (count==1){
            XToast.error(NewExceptionActivity.this, "添加視頻超過最大數量").show();
        }else{
            //
            Intent intent = new Intent();
            intent.setClass(NewExceptionActivity.this, VideoRecordActivity.class);

            startActivityForResult(intent, i);
        }
    }

    @RequiresApi(api = Build.VERSION_CODES.N)
    private void addPic(MyMediaAdapt adapt,int i) {
        long counts = adapt.getData().stream().filter(p -> p.getItemPicEntity() != null).map(p -> p.getItemPicEntity()).count();
        int count = Integer.parseInt(String.valueOf(counts));
        if (count == 1) {
            XToast.error(NewExceptionActivity.this, "添加圖片超過最大數量").show();
        } else {
            setImage(i);

        }
    }

}
